<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS类</title>
</head>
<body>
<p id="demo"></p>
<script>
    /*
    * 使用关键字 class 创建一个类。始终添加一个名为 constructor() 的方法
    * */
    class Car{
        constructor(name,year) {
            this.name = name;
            this.year = year;
        }
        age(x){
            return x - this.year;
        }
    }

    let date = new Date();
    let year = date.getFullYear();

    let myCar = new Car("Ford",2014);
    document.getElementById("demo").innerHTML =
        "My car is " + myCar.age(year) + " years old.";
</script>
</body>
</html>